<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2020/6/22
 * Time: 14:35
 */

namespace app\commi\controller;

use think\Db;
use think\Request;

class Match extends Base
{
    /**
     * 赛事列表
     * @return mixed|\think\response\Json
     */
    public function index(){
        if(request()->isAjax ()){
//            $match_start_time = input('match_start_time');
//            $match_end_time = input('match_end_time');
//            $apply_start_time = input('apply_start_time');
//            $apply_end_time = input('apply_end_time');
//            $keyword = trim(input('keyword'), ' ');
//            $match_status = input('match_status');
//            $match_cate = input('match_cate');
            $where['match_committee_id'] = session('com_id');
            $where['match_member_id'] = session('cm_id');
            // 比赛时间
//            if(isset($match_start_time) && $match_start_time != '' && isset($match_end_time) && $match_end_time != ''){
//                $where['match_start_time'] = ['>=', $match_start_time];
//                $where['match_end_time'] = ['<=', $match_end_time];
//            }
//            if(isset($match_start_time) && $match_start_time != '' && isset($match_end_time) && $match_end_time == ''){
//                $where['match_start_time'] = ['>=', $match_start_time];
//            }
//            if(isset($match_start_time) && $match_start_time == '' && isset($match_end_time) && $match_end_time != ''){
//                $where['match_end_time'] = ['<=', $match_end_time];
//            }
//            // 比赛报名时间
//            if(isset($apply_start_time) && $apply_start_time != '' && isset($apply_end_time) && $apply_end_time != ''){
//                $where['match_apply_start_time'] = ['>=', $apply_start_time];
//                $where['match_apply_end_time'] = ['<=', $apply_end_time];
//            }
//            if(isset($apply_start_time) && $apply_start_time != '' && isset($apply_end_time) && $apply_end_time == ''){
//                $where['match_apply_start_time'] = ['>=', $apply_start_time];
//            }
//            if(isset($apply_start_time) && $apply_start_time == '' && isset($apply_end_time) && $apply_end_time != ''){
//                $where['match_apply_end_time'] = ['<=', $apply_end_time];
//            }
//            // 关键字
//            if(isset($keyword) && $keyword != ''){
//                $where['match_id|match_title'] = ['like', '%' . $keyword . '%'];
//            }
//            // 赛事状态
//            if(isset($match_status) && $match_status != ''){
//                $where['match_status'] = $match_status;
//            }
//            // 赛事分类
//            if(isset($match_cate) && $match_cate != ''){
//                $where['match_cate'] = $match_cate;
//            }
            
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('match')
//                ->join('up_boat', 'match_boat_id = boat_id', 'left')
                ->join('up_u_user', 'match_zong_user_id = user_id', 'left')
                ->where($where)
                ->count();// 获取总条数
            $lists = Db::name('match')
//                ->join('up_boat', 'match_boat_id = boat_id', 'left')
                ->join('up_u_user', 'match_zong_user_id = user_id', 'left')
                ->field('match_id, match_title, match_addr, match_apply_start_time, match_apply_end_time, 
                match_start_time, match_end_time, match_create_time, match_status, match_apply_num, 
                match_zong_user_id, match_zhong_user_id, match_bianpai_user_id, match_zhuren_user_id, 
                match_mishu_user_id, match_hexiao_user_id, match_cate, user_username, match_boat_id')
                ->where($where)
                ->page($Nowpage,$limits)
                ->order('match_create_time desc')
                ->select();
            
            foreach($lists as $k => $v){
                // 赛事时间
                $match_time = date('Y-m-d H:i', strtotime($v['match_start_time'])) . '~' . date('Y-m-d H:i', strtotime($v['match_end_time']));
                $lists[$k]['match_time'] = $match_time;
                // 赛事报名时间
                $match_apply_time = date('Y-m-d H:i', strtotime($v['match_apply_start_time'])) . '~' . date('Y-m-d H:i', strtotime($v['match_apply_end_time']));
                $lists[$k]['match_apply_time'] = $match_apply_time;
                // 船型
                $boat = Db::table('up_boat')
                    ->where('boat_id', 'IN', $v['match_boat_id'])
                    ->column('boat_name');
                $lists[$k]['boat_name'] = implode(',', $boat);
                // 总裁判
//                $zongcai = Db::table('up_u_user')
//                    ->where('user_id', 'IN', $v['match_zong_user_id'])
//                    ->column('user_username');
//                $lists[$k]['zongcai'] = implode(',', $zongcai);
                // 终点裁判
                $zhong = Db::table('up_u_user')
                    ->where('user_id', 'IN', trim($v['match_zhong_user_id'], ','))
                    ->column('user_username');
                $lists[$k]['zhong'] = implode(',', $zhong);
                // 编排长
                $bianpai = Db::table('up_u_user')
                    ->where('user_id', 'IN', trim($v['match_bianpai_user_id'], ','))
                    ->column('user_username');
                $lists[$k]['bianpai'] = implode(',', $bianpai);
                // 仲裁主任
                $zhuren = Db::table('up_u_user')
                    ->where('user_id', 'IN', trim($v['match_zhuren_user_id'], ','))
                    ->column('user_username');
                $lists[$k]['zhuren'] = implode(',', $zhuren);
                // 仲裁秘书
                $mishu = Db::table('up_u_user')
                    ->where('user_id', 'IN', trim($v['match_mishu_user_id'], ','))
                    ->column('user_username');
                $lists[$k]['mishu'] = implode(',', $mishu);
                // 竞赛检录
                $hexiao = Db::table('up_u_user')
                    ->where('user_id', 'IN', trim($v['match_hexiao_user_id'], ','))
                    ->column('user_username');
                $lists[$k]['hexiao'] = implode(',', $hexiao);
                // 报名人数
                $apply_num = Db::table('up_match_apply_info')
                    ->where('ma_match_id', $v['match_id'])
                    ->where('ma_role', 1)
                    ->where('ma_apply_status', 2)
                    ->count();
                $lists[$k]['apply_num'] = $apply_num;
            }
            
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $role = Db::table('up_committee_member')->where('cm_id', session('cm_id'))->value('cm_member_role');
        $match_num = Db::table('up_match')
            ->where('match_committee_id', session('com_id'))
            ->where('match_member_id', session('cm_id'))
            ->count();
        $this->assign([
            'num' => $match_num,
            'role' => $role
        ]);
        return $this->fetch();
    }
    
    /**
     * 添加帆船赛事
     * @return mixed|\think\response\Json
     */
    public function sailboatAdd(){
        if(Request::instance()->isPost()){
            $match_title = trim(input('match_title'), ' ');
            $match_image = input('match_image');
            $match_sheng = input('match_sheng');
            $match_shi = input('match_shi');
            $match_qu = input('match_qu');
            $match_addr = input('match_addr');
            $match_lon = input('match_lon');
            $match_lat = input('match_lat');
            $match_apply_sheng = input('match_apply_sheng');
            $match_apply_shi = input('match_apply_shi');
            $match_apply_qu = input('match_apply_qu');
            $match_apply_addr = input('match_apply_addr');
            $match_start_time = input('match_start_time');
            $match_end_time = input('match_end_time');
            $match_apply_start_time = input('match_apply_start_time');
            $match_apply_end_time = input('match_apply_end_time');
            $match_committee_phone = input('match_committee_phone');
            $match_boat_id = input('match_boat_id');
            $match_country_name = trim(input('match_country_name'), ' ');
            $match_lunci = input('match_lunci');
            $match_apply_lon = input('match_apply_lon');
            $match_apply_lat = input('match_apply_lat');
            $match_mark_lunci = input('match_mark_lunci');
            $match_mark_max_num = input('match_mark_max_num');
            if(!$match_addr){
                return json(['code' => 100, 'msg' => '请选择比赛地址']);
            }
            if(!$match_apply_addr){
                return json(['code' => 100, 'msg' => '请选择报到地址']);
            }
            if($match_mark_lunci >= $match_lunci) return json(['code' => 100, 'msg' => '成绩计算限制轮次不能大于比赛轮次']);
            if($match_mark_lunci + $match_mark_max_num > $match_lunci) return json(['code' => 100, 'msg' => '可去除最大个数与限制轮次之和不能大于比赛轮次']);
            $insert = [
                'match_committee_id' => session('com_id'),
                'match_member_id' => session('cm_id'),
                'match_title' => $match_title,
                'match_image' => $match_image,
                'match_boat_id' => $match_boat_id,
                'match_committee_phone' => $match_committee_phone,
                'match_apply_start_time' => $match_apply_start_time,
                'match_apply_end_time' => $match_apply_end_time,
                'match_start_time' => $match_start_time,
                'match_end_time' => $match_end_time,
                'match_sheng' => $match_sheng,
                'match_shi' => $match_shi,
                'match_qu' => $match_qu,
                'match_lon' => $match_lon,
                'match_lat' => $match_lat,
                'match_addr' => $match_addr,
                'match_apply_sheng' => $match_apply_sheng,
                'match_apply_shi' => $match_apply_shi,
                'match_apply_qu' => $match_apply_qu,
                'match_apply_lon' => $match_apply_lon,
                'match_apply_lat' => $match_apply_lat,
                'match_apply_addr' => $match_apply_addr,
                'match_cate' => 1,
                'match_create_time' => date('Y-m-d H:i:s'),
                'match_country_name' => $match_country_name,
                'match_lunci' => $match_lunci,
                'match_mark_lunci' => $match_mark_lunci,
                'match_mark_max_num' => $match_mark_max_num
            ];
            $res = Db::table('up_match')->insert($insert);
            if($res){
                return json(['code' => 200, 'msg' => '添加成功']);
            }else{
                return json(['code' => 100, 'msg' => '添加失败']);
            }
        }
        // 省
        $province = Db::table('up_area')->where('level', 1)->field('district_id, district')->select();
        // 组别
        $group = Db::table('up_match_group')
            ->where('mg_status', 1)
            ->where('mg_cate', 1)
            ->field('mg_id, mg_name')
            ->select();
        // 船型
        $boat = Db::table('up_boat')->field('boat_id, boat_name')->select();
        $this->assign([
            'province' => $province,
            'group' => $group,
            'boat' => $boat
        ]);
        $lose = $this->lostTime();
        if($lose == 1){
            return $this->fetch('/lose');
        }else{
            return $this->fetch('match/sailboatadd');
        }
    }
    
    /**
     * 编辑帆船赛事
     * @return mixed|\think\response\Json
     */
    public function sailboatEdit(){
        $match_id = input('match_id');
        if(Request::instance()->isPost()){
            $match_title = trim(input('match_title'), ' ');
            $match_image = input('match_image');
            $match_sheng = input('match_sheng');
            $match_shi = input('match_shi');
            $match_qu = input('match_qu');
            $match_addr = input('match_addr');
            $match_lon = input('match_lon');
            $match_lat = input('match_lat');
            $match_apply_sheng = input('match_apply_sheng');
            $match_apply_shi = input('match_apply_shi');
            $match_apply_qu = input('match_apply_qu');
            $match_apply_addr = input('match_apply_addr');
            $match_start_time = input('match_start_time');
            $match_end_time = input('match_end_time');
            $match_apply_start_time = input('match_apply_start_time');
            $match_apply_end_time = input('match_apply_end_time');
            $match_committee_phone = input('match_committee_phone');
            $match_boat_id = input('match_boat_id');
            $match_country_name = trim(input('match_country_name'), ' ');
            $match_lunci = input('match_lunci');
            $match_apply_lon = input('match_apply_lon');
            $match_apply_lat = input('match_apply_lat');
            $match_mark_lunci = input('match_mark_lunci');
            $match_mark_max_num = input('match_mark_max_num');
            if(!$match_addr){
                return json(['code' => 100, 'msg' => '请选择比赛地址']);
            }
            if(!$match_apply_addr){
                return json(['code' => 100, 'msg' => '请选择报到地址']);
            }
            if($match_mark_lunci >= $match_lunci) return json(['code' => 100, 'msg' => '成绩计算限制轮次不能大于比赛轮次']);
            if($match_mark_lunci + $match_mark_max_num > $match_lunci) return json(['code' => 100, 'msg' => '可去除最大个数与限制轮次之和不能大于比赛轮次']);
            $update = [
                'match_title' => $match_title,
                'match_boat_id' => $match_boat_id,
                'match_committee_phone' => $match_committee_phone,
                'match_apply_start_time' => $match_apply_start_time,
                'match_apply_end_time' => $match_apply_end_time,
                'match_start_time' => $match_start_time,
                'match_end_time' => $match_end_time,
                'match_sheng' => $match_sheng,
                'match_shi' => $match_shi,
                'match_qu' => $match_qu,
                'match_lon' => $match_lon,
                'match_lat' => $match_lat,
                'match_addr' => $match_addr,
                'match_apply_sheng' => $match_apply_sheng,
                'match_apply_shi' => $match_apply_shi,
                'match_apply_qu' => $match_apply_qu,
                'match_apply_lon' => $match_apply_lon,
                'match_apply_lat' => $match_apply_lat,
                'match_apply_addr' => $match_apply_addr,
                'match_country_name' => $match_country_name,
                'match_lunci' => $match_lunci,
                'match_mark_lunci' => $match_mark_lunci,
                'match_mark_max_num' => $match_mark_max_num
            ];
            if(!empty($match_image)){
                $update['match_image'] = $match_image;
            }
            $res = Db::table('up_match')->where('match_id', $match_id)->update($update);
            if($res){
                return json(['code' => 200, 'msg' => '编辑成功']);
            }else{
                return json(['code' => 100, 'msg' => '编辑失败']);
            }
        }
        $match = Db::table('up_match')
            ->where('match_id', $match_id)
            ->field('match_title, match_image, match_boat_id, match_committee_phone, 
            match_apply_start_time, match_apply_end_time, match_start_time, match_end_time, match_lunci, 
            match_sheng, match_shi, match_qu, match_lon, match_lat, match_addr, match_apply_sheng, 
            match_apply_shi, match_apply_qu, match_apply_addr, match_country_name, match_apply_lon, 
            match_apply_lat, match_mark_lunci, match_mark_max_num')
            ->find();
        $province = Db::table('up_area')->where('level', 1)->field('district_id, district')->select();
        $city = Db::table('up_area')
            ->where('level', 2)
            ->where('pid', $match['match_sheng'])
            ->field('district_id, district')
            ->select();
        $district = Db::table('up_area')
            ->where('level', 3)
            ->where('pid', $match['match_shi'])
            ->field('district_id, district')
            ->select();
        $cityA = Db::table('up_area')
            ->where('level', 2)
            ->where('pid', $match['match_apply_sheng'])
            ->field('district_id, district')
            ->select();
        $districtA = Db::table('up_area')
            ->where('level', 3)
            ->where('pid', $match['match_apply_shi'])
            ->field('district_id, district')
            ->select();
        // 船型
        $boat = Db::table('up_boat')->field('boat_id, boat_name')->select();
        $this->assign([
            'match_id' => $match_id,
            'match' => $match,
            'province' => $province,
            'city' => $city,
            'district' => $district,
            'cityA' => $cityA,
            'districtA' => $districtA,
            'boat' => $boat
        ]);
        $lose = $this->lostTime();
        if($lose == 1){
            return $this->fetch('/lose');
        }else{
            return $this->fetch('match/sailboatedit');
        }
    }
    
    /**
     * 帆船起航数据
     * @return mixed|\think\response\Json
     */
    public function sailData(){
        $match = Db::table('up_match')
            ->where('match_committee_id', session('com_id'))
            ->field('match_id, match_lunci')
            ->find();
        $group = Db::table('up_match_apply_group')
            ->join('up_match_group', 'mg_id = mag_group_id', 'left')
            ->where('mag_match_id', $match['match_id'])
            ->field('mg_id, mg_name')
            ->select();
        $lunci = range(1, $match['match_lunci']);
        if(request()->isAjax ()){
            $group_id = input('group_id'); //  组
            $lc_id = input('lc_id'); // 轮次
            $where['umd.match_id'] = $match['match_id'];
            if(isset($group_id) && $group_id != ''){
                $where['umd.level_id'] = $group_id;
            }
            /*else{
                $where['umd.level_id'] = $group[0]['mg_id'];
            }*/
            if(isset($lc_id) && $lc_id != ''){
                $where['umd.turn'] = $lc_id;
            }
            /*else{
                $where['umd.turn'] = $lunci[0];
            }*/
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::table('up__match_arrive_record')
                ->alias('umar')
                ->join('up__match_detail umd', 'umar.match_detail_id = umd.id', 'left')
                ->where($where)
                ->count();// 获取总条数
            $count2 = Db::table('up__match_arrive_record')
                ->alias('umar')
                ->join('up__match_detail umd', 'umar.match_detail_id = umd.id', 'left')
                ->where($where)
                ->column('umar.id');// 获取总条数
            $lists = Db::table('up__match_arrive_record')
                ->alias('umar')
                ->join('up__match_detail umd', 'umar.match_detail_id = umd.id', 'left')
                ->field('umar.id, umd.match_id, umar.temp_score, umar.sensor_id, umd.turn, umar.start_line_time, 
                umar.start_line_location, umar.start_line_speed, umar.angle')
                ->where($where)
                ->page($Nowpage,$limits)
                ->order('umar.start_line_time asc')
                ->select();
            foreach($lists as $k => $v){
                // 名次
                $lists[$k]['mc'] = $k + 1;
                // 报名信息
                if($v['sensor_id']){
                    $sensor = explode('_', $v['sensor_id']);
                    $user = Db::table('up_u_user')
                        ->where('user_id', $sensor[1])
                        ->field('user_real_name')
                        ->find();
                    $apply = Db::table('up_match_apply_info')
                        ->join('up_club', 'ma_club_id = club_id', 'left')
                        ->where('ma_user_id', $sensor[1])
                        ->where('ma_match_id', $v['match_id'])
                        ->field('ma_fan_code, club_name')
                        ->find();
                    $lists[$k]['fan_code'] = $apply['ma_fan_code'];
                    $lists[$k]['club_name'] = $apply['club_name'];
                    $lists[$k]['user_real_name'] = $user['user_real_name'];
                }
            }
            $str = '';
            if($count2){
                $str = implode($count2,',');
            }
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'count2' => $str, 'data' => $lists]);
        }
    
        $this->assign([
            'group' => $group,
            'lunci' => $lunci,
        ]);
        return $this->fetch('match/saildata');
    }
    
    /**
     * 添加赛艇赛事
     * @return mixed|\think\response\Json
     */
    public function rowingAdd(){
        if(Request::instance()->isPost()){
            $match_title = trim(input('match_title'), ' ');
            $match_image = input('match_image');
            $match_sheng = input('match_sheng');
            $match_shi = input('match_shi');
            $match_qu = input('match_qu');
            $match_addr = input('match_addr');
            $match_lon = input('match_lon');
            $match_lat = input('match_lat');
            $match_apply_sheng = input('match_apply_sheng');
            $match_apply_shi = input('match_apply_shi');
            $match_apply_qu = input('match_apply_qu');
            $match_apply_addr = input('match_apply_addr');
            $match_start_time = input('match_start_time');
            $match_end_time = input('match_end_time');
            $match_apply_start_time = input('match_apply_start_time');
            $match_apply_end_time = input('match_apply_end_time');
            $match_committee_phone = input('match_committee_phone');
            $match_stop_time = input('match_stop_time');
            $match_country_name = trim(input('match_country_name'), ' ');
//            $match_lunci = input('match_lunci');
            $match_apply_lon = input('match_apply_lon');
            $match_apply_lat = input('match_apply_lat');
            $match_saidao_num = input('match_saidao_num');
    
            if(!$match_addr){
                return json(['code' => 100, 'msg' => '请选择比赛地址']);
            }
            if(!$match_apply_addr){
                return json(['code' => 100, 'msg' => '请选择报到地址']);
            }
        
            $insert = [
                'match_committee_id' => session('com_id'),
                'match_member_id' => session('cm_id'),
                'match_title' => $match_title,
                'match_image' => $match_image,
                'match_committee_phone' => $match_committee_phone,
                'match_apply_start_time' => $match_apply_start_time,
                'match_apply_end_time' => $match_apply_end_time,
                'match_start_time' => $match_start_time,
                'match_end_time' => $match_end_time,
                'match_sheng' => $match_sheng,
                'match_shi' => $match_shi,
                'match_qu' => $match_qu,
                'match_lon' => $match_lon,
                'match_lat' => $match_lat,
                'match_addr' => $match_addr,
                'match_apply_sheng' => $match_apply_sheng,
                'match_apply_shi' => $match_apply_shi,
                'match_apply_qu' => $match_apply_qu,
                'match_apply_lon' => $match_apply_lon,
                'match_apply_lat' => $match_apply_lat,
                'match_apply_addr' => $match_apply_addr,
                'match_cate' => 2,
                'match_create_time' => date('Y-m-d H:i:s'),
                'match_stop_time' => $match_stop_time,
                'match_country_name' => $match_country_name,
//                'match_lunci' => $match_lunci,
                'match_saidao_num' => $match_saidao_num
            ];
            $res = Db::table('up_match')->insert($insert);
            if($res){
                return json(['code' => 200, 'msg' => '添加成功']);
            }else{
                return json(['code' => 100, 'msg' => '添加失败']);
            }
        }
        // 省
        $province = Db::table('up_area')->where('level', 1)->field('district_id, district')->select();
        
        $this->assign([
            'province' => $province
        ]);
        $lose = $this->lostTime();
        if($lose == 1){
            return $this->fetch('/lose');
        }else{
            return $this->fetch('match/rowingadd');
        }
    }
    
    /**
     * 编辑赛艇信息
     * @return mixed|\think\response\Json
     */
    public function rowingEdit(){
        $match_id = input('match_id');
        if(Request::instance()->isPost()){
            $match_title = trim(input('match_title'), ' ');
            $match_image = input('match_image');
            $match_sheng = input('match_sheng');
            $match_shi = input('match_shi');
            $match_qu = input('match_qu');
            $match_addr = input('match_addr');
            $match_lon = input('match_lon');
            $match_lat = input('match_lat');
            $match_apply_sheng = input('match_apply_sheng');
            $match_apply_shi = input('match_apply_shi');
            $match_apply_qu = input('match_apply_qu');
            $match_apply_addr = input('match_apply_addr');
            $match_start_time = input('match_start_time');
            $match_end_time = input('match_end_time');
            $match_apply_start_time = input('match_apply_start_time');
            $match_apply_end_time = input('match_apply_end_time');
            $match_committee_phone = input('match_committee_phone');
            $match_stop_time = input('match_stop_time');
            $match_country_name = trim(input('match_country_name'), ' ');
//            $match_lunci = input('match_lunci');
            $match_apply_lon = input('match_apply_lon');
            $match_apply_lat = input('match_apply_lat');
            $match_saidao_num = input('match_saidao_num');
    
            if(!$match_addr){
                return json(['code' => 100, 'msg' => '请选择比赛地址']);
            }
            if(!$match_apply_addr){
                return json(['code' => 100, 'msg' => '请选择报到地址']);
            }
        
            $update = [
                'match_title' => $match_title,
                'match_committee_phone' => $match_committee_phone,
                'match_apply_start_time' => $match_apply_start_time,
                'match_apply_end_time' => $match_apply_end_time,
                'match_start_time' => $match_start_time,
                'match_end_time' => $match_end_time,
                'match_sheng' => $match_sheng,
                'match_shi' => $match_shi,
                'match_qu' => $match_qu,
                'match_lon' => $match_lon,
                'match_lat' => $match_lat,
                'match_addr' => $match_addr,
                'match_apply_sheng' => $match_apply_sheng,
                'match_apply_shi' => $match_apply_shi,
                'match_apply_qu' => $match_apply_qu,
                'match_apply_lon' => $match_apply_lon,
                'match_apply_lat' => $match_apply_lat,
                'match_apply_addr' => $match_apply_addr,
                'match_stop_time' => $match_stop_time,
                'match_country_name' => $match_country_name,
//                'match_lunci' => $match_lunci,
                'match_saidao_num' => $match_saidao_num
            ];
            if(!empty($match_image)){
                $update['match_image'] = $match_image;
            }
            $res = Db::table('up_match')->where('match_id', $match_id)->update($update);
            if($res){
                return json(['code' => 200, 'msg' => '编辑成功']);
            }else{
                return json(['code' => 100, 'msg' => '编辑失败']);
            }
        }
        $match = Db::table('up_match')
            ->where('match_id', $match_id)
            ->field('match_title, match_image, match_committee_phone, match_apply_start_time, 
            match_apply_end_time, match_start_time, match_end_time, match_sheng, match_shi, match_qu, 
            match_lon, match_lat, match_addr, match_apply_sheng, match_apply_shi, match_apply_qu, 
            match_apply_addr, match_stop_time, match_country_name, match_apply_lon, match_apply_lat, 
            match_saidao_num')
            ->find();
        $province = Db::table('up_area')->where('level', 1)->field('district_id, district')->select();
        $city = Db::table('up_area')
            ->where('level', 2)
            ->where('pid', $match['match_sheng'])
            ->field('district_id, district')
            ->select();
        $district = Db::table('up_area')
            ->where('level', 3)
            ->where('pid', $match['match_shi'])
            ->field('district_id, district')
            ->select();
        $cityA = Db::table('up_area')
            ->where('level', 2)
            ->where('pid', $match['match_apply_sheng'])
            ->field('district_id, district')
            ->select();
        $districtA = Db::table('up_area')
            ->where('level', 3)
            ->where('pid', $match['match_apply_shi'])
            ->field('district_id, district')
            ->select();
        
        $this->assign([
            'match_id' => $match_id,
            'match' => $match,
            'province' => $province,
            'city' => $city,
            'district' => $district,
            'cityA' => $cityA,
            'districtA' => $districtA
        ]);
        $lose = $this->lostTime();
        if($lose == 1){
            return $this->fetch('/lose');
        }else{
            return $this->fetch('match/rowingedit');
        }
    }
    
    /**
     * 赛艇起航数据
     */
    public function rowingData(){
        
    }
    
    /**
     * 生活信息列表
     * @return mixed|\think\response\Json
     */
    public function matchLife(){
        if(request()->isAjax ()){
            $where['ml_match_id'] = session('match_id');
        
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('match_life')
                ->where($where)
                ->count();// 获取总条数
            $lists = Db::name('match_life')
                ->field('ml_id, ml_type')
                ->where($where)
                ->page($Nowpage,$limits)
                ->order('ml_id desc')
                ->select();
        
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $match_id = input('match_id');
        if(isset($match_id) && !empty($match_id)){
            session('match_id', $match_id);
        }
        return $this->fetch('match/matchlife');
    }
    
    /**
     * 添加生活信息
     * @return mixed|\think\response\Json
     */
    public function lifeAdd(){
        if(Request::instance()->isPost()){
            $ml_type = input('ml_type');
            $ml_match_id = session('match_id');
            $ml_content = input('ml_content');
            $exist = Db::table('up_match_life')
                ->where('ml_type', $ml_type)
                ->where('ml_match_id', $ml_match_id)
                ->find();
            if($exist){
                return json(['code' => 100, 'msg' => '已添加过相同类型的生活信息']);
            }
            $insert = [
                'ml_type' => $ml_type,
                'ml_match_id' => $ml_match_id,
                'ml_content' => $ml_content
            ];
            $res = Db::table('up_match_life')->insert($insert);
            if($res){
                return json(['code' => 200, 'msg' => '添加成功']);
            }else{
                return json(['code' => 100, 'msg' => '添加失败']);
            }
        }
        $lose = $this->lostTime();
        if($lose == 1){
            return $this->fetch('/lose');
        }else{
            return $this->fetch('match/lifeadd');
        }
    }
    
    /**
     * 生活信息详情
     * @return mixed
     */
    public function lifeDetail(){
        $ml_id = input('ml_id');
        $life = Db::table('up_match_life')
            ->field('ml_content')
            ->where('ml_id', $ml_id)
            ->find();
        $this->assign('life', $life);
        return $this->fetch('match/lifedetail');
    }
    
    /**
     * 编辑生活信息
     * @return mixed|\think\response\Json
     */
    public function lifeEdit(){
        $ml_id = input('ml_id');
        if(Request::instance()->isPost()){
            $ml_type = input('ml_type');
            $ml_match_id = session('match_id');
            $ml_content = input('ml_content');
            $exist = Db::table('up_match_life')
                ->where('ml_type', $ml_type)
                ->where('ml_match_id', $ml_match_id)
                ->where('ml_id', 'NEQ', $ml_id)
                ->find();
            if($exist){
                return json(['code' => 100, 'msg' => '已添加过相同类型的生活信息']);
            }
            $update = [
                'ml_type' => $ml_type,
                'ml_content' => $ml_content
            ];
            $res = Db::table('up_match_life')->where('ml_id', $ml_id)->update($update);
            if($res){
                return json(['code' => 200, 'msg' => '编辑成功']);
            }else{
                return json(['code' => 100, 'msg' => '编辑失败']);
            }
        }
        $life = Db::table('up_match_life')
            ->field('ml_content, ml_type')
            ->where('ml_id', $ml_id)
            ->find();
        $this->assign([
            'life' => $life,
            'ml_id' => $ml_id
        ]);
        $lose = $this->lostTime();
        if($lose == 1){
            return $this->fetch('/lose');
        }else{
            return $this->fetch('match/lifeedit');
        }
    }
    
    /**
     * 生活信息附件
     * @return mixed|\think\response\Json
     */
    public function lifeFiles(){
        if(request()->isAjax ()){
            $where['mli_life_id'] = session('ml_id');
        
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('match_life_info')
                ->where($where)
                ->count();// 获取总条数
            $lists = Db::name('match_life_info')
                ->field('mli_id, mli_name, mli_url, mli_dis')
                ->where($where)
                ->page($Nowpage,$limits)
                ->order('mli_id desc')
                ->select();
        
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $ml_id = input('ml_id');
        if(isset($ml_id) && !empty($ml_id)){
            session('ml_id', $ml_id);
        }
        return $this->fetch('match/lifefiles');
    }
    
    /**
     * 添加文件
     * @return mixed|\think\response\Json
     */
    public function filesAdd(){
        if(Request::instance()->isPost()){
            $mli_name = trim(input('mli_name'), ' ');
            $mli_url = input('mli_url');
            $mli_dis = input('mli_dis');
            $insert = [
                'mli_life_id' => session('ml_id'),
                'mli_name' => $mli_name,
                'mli_url' => $mli_url,
                'mli_dis' => $mli_dis
            ];
            $res = Db::table('up_match_life_info')->insert($insert);
            if($res){
                return json(['code' => 200, 'msg' => '添加成功']);
            }else{
                return json(['code' => 100, 'msg' => '添加失败']);
            }
        }
        $lose = $this->lostTime();
        if($lose == 1){
            return $this->fetch('/lose');
        }else{
            return $this->fetch('match/filesadd');
        }
    }
    
    /**
     * 编辑文件
     * @return mixed|\think\response\Json
     */
    public function filesEdit(){
        $mli_id = input('mli_id');
        if(Request::instance()->isPost()){
            $mli_name = trim(input('mli_name'), ' ');
            $mli_url = input('mli_url');
            $mli_dis = input('mli_dis');
            $update = [
                'mli_name' => $mli_name,
                'mli_dis' => $mli_dis
            ];
            if(!empty($mli_url)){
                $update['mli_url'] = $mli_url;
            }
            $res = Db::table('up_match_life_info')->where('mli_id', $mli_id)->update($update);
            if($res){
                return json(['code' => 200, 'msg' => '编辑成功']);
            }else{
                return json(['code' => 100, 'msg' => '编辑失败']);
            }
        }
        $file = Db::table('up_match_life_info')
            ->field('mli_name, mli_url, mli_dis')
            ->where('mli_id', $mli_id)
            ->find();
        $this->assign([
            'file' => $file,
            'mli_id' => $mli_id
        ]);
        $lose = $this->lostTime();
        if($lose == 1){
            return $this->fetch('/lose');
        }else{
            return $this->fetch('match/filesedit');
        }
    }
    
    /**
     * 删除文件
     * @return \think\response\Json
     */
    public function filesDel(){
        $lose = $this->lostTime();
        if($lose == 1){
            return json(['code' => 100, 'msg' => '账号已过期，非法操作']);
        }
        $mli_id = input('id');
        $res = Db::table('up_match_life_info')->delete($mli_id);
        if($res){
            return json(['code' => 200, 'msg' => '删除成功']);
        }else{
            return json(['code' => 100, 'msg' => '删除失败']);
        }
    }
    
    /**
     * 临时通知
     * @return mixed|\think\response\Json
     */
    public function matchLs(){
        if(request()->isAjax ()){
            $where['mfls_match_id'] = session('match_id');
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('match_ls')
                ->where($where)
                ->count();// 获取总条数
            $lists = Db::name('match_ls')
                ->field('mfls_id, mfls_title, mfls_match_intro, mfls_time')
                ->where($where)
                ->page($Nowpage,$limits)
                ->order('mfls_time desc')
                ->select();
        
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $match_id = input('match_id');
        if(isset($match_id) && !empty($match_id)){
            session('match_id', $match_id);
        }
        return $this->fetch('match/matchls');
    }
    
    /**
     * 发布临时通知
     * @return mixed|\think\response\Json
     */
    public function lsAdd(){
        if(Request::instance()->isPost()){
            $mfls_title = trim(input('mfls_title'), ' ');
            $mfls_match_intro = input('mfls_match_intro');
            $insert = [
                'mfls_match_id' => session('match_id'),
                'mfls_title' => $mfls_title,
                'mfls_match_intro' => $mfls_match_intro,
                'mfls_read_user' => ',0,',
                'mfls_del_user' => ',0,',
                'mfls_time' => date('Y-m-d H:i:s')
            ];
            $res = Db::table('up_match_ls')->insertGetId($insert);
            if($res){
                $commi_member = Db::table('up_committee_member')
                    ->where('cm_match_id', session('match_id'))
                    ->column('cm_match_user_id');
                $join = Db::table('up_match_apply_info')
                    ->where('ma_match_id', session('match_id'))
                    ->column('ma_user_id');
                $ids_arr = array_merge($commi_member, $join);
                if(!$ids_arr){
                    $new = array_unique($ids_arr);
                    $list = [];
                    foreach($new as $k => $v){
                        array_push($list, (string)$v);
                    }
                    try{
                        $this->Jpush(1, $list, '文件通知', ['send_type' => 3, 'mfls_id' => $res]);
                    }catch(\Exception $e){
            
                    }
                }
                return json(['code' => 200, 'msg' => '添加成功']);
            }else{
                return json(['code' => 100, 'msg' => '添加失败']);
            }
        }
        $lose = $this->lostTime();
        if($lose == 1){
            return $this->fetch('/lose');
        }else{
            return $this->fetch('match/lsadd');
        }
    }
    
    /**
     * 编辑临时通知
     * @return mixed|\think\response\Json
     */
    public function lsEdit(){
        $mfls_id = input('mfls_id');
        if(Request::instance()->isPost()){
            $mfls_title = trim(input('mfls_title'), ' ');
            $mfls_match_intro = input('mfls_match_intro');
            $update = [
                'mfls_title' => $mfls_title,
                'mfls_match_intro' => $mfls_match_intro,
            ];
            $res = Db::table('up_match_ls')->where('mfls_id', $mfls_id)->update($update);
            if($res){
                return json(['code' => 200, 'msg' => '编辑成功']);
            }else{
                return json(['code' => 100, 'msg' => '编辑失败']);
            }
        }
        $ls = Db::table('up_match_ls')
            ->field('mfls_title, mfls_match_intro')
            ->where('mfls_id', $mfls_id)
            ->find();
        $this->assign([
            'ls' => $ls,
            'mfls_id' => $mfls_id
        ]);
        $lose = $this->lostTime();
        if($lose == 1){
            return $this->fetch('/lose');
        }else{
            return $this->fetch('match/lsedit');
        }
    }
    
    /**
     * 删除临时通知
     * @return \think\response\Json
     */
    public function lsDel(){
        $lose = $this->lostTime();
        if($lose == 1){
            return json(['code' => 100, 'msg' => '账号已过期，非法操作']);
        }
        $mfls_id = input('id');
        Db::startTrans();
        try{
            Db::table('up_match_ls')->delete($mfls_id);
            Db::table('up_match_ls_files')->where('mll_ls_id', $mfls_id)->delete();
            Db::commit();
            return json(['code' => 200, 'msg' => '删除成功']);
        }catch(\Exception $e){
            Db::rollback();
            return json(['code' => 100, 'msg' => '删除失败']);
        }
    }
    
    /**
     * 临时通知文件
     * @return mixed|\think\response\Json
     */
    public function lsFiles(){
        if(request()->isAjax ()){
            $where['mll_ls_id'] = session('mfls_id');
        
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('match_ls_files')
                ->where($where)
                ->count();// 获取总条数
            $lists = Db::name('match_ls_files')
                ->field('mll_id, mll_file_url, mll_file_name, mll_file_bmp')
                ->where($where)
                ->page($Nowpage,$limits)
                ->order('mll_id desc')
                ->select();
        
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $mfls_id = input('mfls_id');
        if(isset($mfls_id) && !empty($mfls_id)){
            session('mfls_id', $mfls_id);
        }
        return $this->fetch('match/lsfiles');
    }
    
    /**
     * 添加临时通知文件
     * @return mixed|\think\response\Json
     */
    public function lsFilesAdd(){
        if(Request::instance()->isPost()){
            $mll_file_name = trim(input('mll_file_name'), ' ');
            $mll_file_url = input('mll_file_url');
            $mll_file_bmp = input('mll_file_bmp');
            $insert = [
                'mll_ls_id' => session('mfls_id'),
                'mll_file_url' => $mll_file_url,
                'mll_file_name' => $mll_file_name,
                'mll_file_bmp' => $mll_file_bmp
            ];
            $res = Db::table('up_match_ls_files')->insert($insert);
            if($res){
                return json(['code' => 200, 'msg' => '添加成功']);
            }else{
                return json(['code' => 100, 'msg' => '添加失败']);
            }
        }
        $lose = $this->lostTime();
        if($lose == 1){
            return $this->fetch('/lose');
        }else{
            return $this->fetch('match/lsfilesadd');
        }
    }
    
    /**
     * 编辑临时通知文件
     * @return mixed|\think\response\Json
     */
    public function lsFilesEdit(){
        $mll_id = input('mll_id');
        if(Request::instance()->isPost()){
            $mll_file_name = trim(input('mll_file_name'), ' ');
            $mll_file_url = input('mll_file_url');
            $mll_file_bmp = input('mll_file_bmp');
            $update = [
                'mll_file_name' => $mll_file_name,
                'mll_file_bmp' => $mll_file_bmp
            ];
            if(!empty($mll_file_url)){
                $update['mll_file_url'] = $mll_file_url;
            }
            $res = Db::table('up_match_ls_files')->where('mll_id', $mll_id)->update($update);
            if($res){
                return json(['code' => 200, 'msg' => '编辑成功']);
            }else{
                return json(['code' => 100, 'msg' => '编辑失败']);
            }
        }
        $file = Db::table('up_match_ls_files')
            ->field('mll_file_url, mll_file_name, mll_file_bmp')
            ->where('mll_id', $mll_id)
            ->find();
        $this->assign([
            'file' => $file,
            'mll_id' => $mll_id
        ]);
        $lose = $this->lostTime();
        if($lose == 1){
            return $this->fetch('/lose');
        }else{
            return $this->fetch('match/lsfilesedit');
        }
    }
    
    /**
     * 删除临时通知文件
     * @return \think\response\Json
     */
    public function lsFilesDel(){
        $lose = $this->lostTime();
        if($lose == 1){
            return json(['code' => 100, 'msg' => '账号已过期，非法操作']);
        }
        $mll_id = input('id');
        $res = Db::table('up_match_ls_files')->delete($mll_id);
        if($res){
            return json(['code' => 200, 'msg' => '删除成功']);
        }else{
            return json(['code' => 100, 'msg' => '删除失败']);
        }
    }
    
    /**
     * 官方文件
     * @return mixed|\think\response\Json
     */
    public function matchGf(){
        if(request()->isAjax ()){
            $where['mgf_match_id'] = session('match_id');
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('match_gf')
                ->where($where)
                ->count();// 获取总条数
            $lists = Db::name('match_gf')
                ->field('mgf_id, mgf_title, mgf_intro, mgf_time')
                ->where($where)
                ->page($Nowpage,$limits)
                ->order('mgf_time desc')
                ->select();
        
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $match_id = input('match_id');
        if(isset($match_id) && !empty($match_id)){
            session('match_id', $match_id);
        }
        return $this->fetch('match/matchgf');
    }
    
    /**
     * 发布官方公告
     * @return mixed|\think\response\Json
     */
    public function gfAdd(){
        if(Request::instance()->isPost()){
            $mgf_title = trim(input('mgf_title'), ' ');
            $mgf_intro = input('mgf_intro');
            $insert = [
                'mgf_match_id' => session('match_id'),
                'mgf_title' => $mgf_title,
                'mgf_intro' => $mgf_intro,
                'mgf_read_user' => ',0,',
                'mgf_del_user' => ',0,',
                'mgf_time' => date('Y-m-d H:i:s')
            ];
            $res = Db::table('up_match_gf')->insert($insert);
            if($res){
                $commi_member = Db::table('up_committee_member')
                    ->where('cm_match_id', session('match_id'))
                    ->column('cm_match_user_id');
                $join = Db::table('up_match_apply_info')
                    ->where('ma_match_id', session('match_id'))
                    ->column('ma_user_id');
                $ids_arr = array_merge($commi_member, $join);
                if(!$ids_arr){
                    $new = array_unique($ids_arr);
                    $list = [];
                    foreach($new as $k => $v){
                        array_push($list, (string)$v);
                    }
                    try{
                        $this->Jpush(1, $list, '文件通知', ['send_type' => 2, 'mgf_id' => $res]);
                    }catch(\Exception $e){
            
                    }
                }
                return json(['code' => 200, 'msg' => '添加成功']);
            }else{
                return json(['code' => 100, 'msg' => '添加失败']);
            }
        }
        $lose = $this->lostTime();
        if($lose == 1){
            return $this->fetch('/lose');
        }else{
            return $this->fetch('match/gfadd');
        }
    }
    
    /**
     * 编辑官方公告
     * @return mixed|\think\response\Json
     */
    public function gfEdit(){
        $mgf_id = input('mgf_id');
        if(Request::instance()->isPost()){
            $mgf_title = trim(input('mgf_title'), ' ');
            $mgf_intro = input('mgf_intro');
            $update = [
                'mgf_title' => $mgf_title,
                'mgf_intro' => $mgf_intro,
            ];
            $res = Db::table('up_match_gf')->where('mgf_id', $mgf_id)->update($update);
            if($res){
                return json(['code' => 200, 'msg' => '编辑成功']);
            }else{
                return json(['code' => 100, 'msg' => '编辑失败']);
            }
        }
        $gf = Db::table('up_match_gf')
            ->field('mgf_title, mgf_intro')
            ->where('mgf_id', $mgf_id)
            ->find();
        $this->assign([
            'gf' => $gf,
            'mgf_id' => $mgf_id
        ]);
        $lose = $this->lostTime();
        if($lose == 1){
            return $this->fetch('/lose');
        }else{
            return $this->fetch('match/gfedit');
        }
    }
    
    /**
     * 删除官方公告
     * @return \think\response\Json
     */
    public function gfDel(){
        $lose = $this->lostTime();
        if($lose == 1){
            return json(['code' => 100, 'msg' => '账号已过期，非法操作']);
        }
        $mgf_id = input('id');
        Db::startTrans();
        try{
            Db::table('up_match_gf')->delete($mgf_id);
            Db::table('up_match_gf_files')->where('mgfff_gf_id', $mgf_id)->delete();
            Db::commit();
            return json(['code' => 200, 'msg' => '删除成功']);
        }catch(\Exception $e){
            Db::rollback();
            return json(['code' => 100, 'msg' => '删除失败']);
        }
    }
    
    /**
     * 官方公告列表
     * @return mixed|\think\response\Json
     */
    public function gfFiles(){
        if(request()->isAjax ()){
            $where['mgfff_gf_id'] = session('mgf_id');
        
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('match_gf_files')
                ->where($where)
                ->count();// 获取总条数
            $lists = Db::name('match_gf_files')
                ->field('mgff_id, mgff_file_url, mgff_file_name, mgff_file_bmp')
                ->where($where)
                ->page($Nowpage,$limits)
                ->order('mgff_id desc')
                ->select();
        
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $mgf_id = input('mgf_id');
        if(isset($mgf_id) && !empty($mgf_id)){
            session('mgf_id', $mgf_id);
        }
        return $this->fetch('match/gffiles');
    }
    
    /**
     * 添加官方公告文件
     * @return mixed|\think\response\Json
     */
    public function gfFilesAdd(){
        if(Request::instance()->isPost()){
            $mgff_file_name = trim(input('mgff_file_name'), ' ');
            $mgff_file_url = input('mgff_file_url');
            $mgff_file_bmp = input('mgff_file_bmp');
            $insert = [
                'mgfff_gf_id' => session('mgf_id'),
                'mgff_file_url' => $mgff_file_url,
                'mgff_file_name' => $mgff_file_name,
                'mgff_file_bmp' => $mgff_file_bmp
            ];
            $res = Db::table('up_match_gf_files')->insert($insert);
            if($res){
                
                return json(['code' => 200, 'msg' => '添加成功']);
            }else{
                return json(['code' => 100, 'msg' => '添加失败']);
            }
        }
        $lose = $this->lostTime();
        if($lose == 1){
            return $this->fetch('/lose');
        }else{
            return $this->fetch('match/gffilesadd');
        }
    }
    
    /**
     * 编辑官方公告文件
     * @return mixed|\think\response\Json
     */
    public function gfFilesEdit(){
        $mgff_id = input('mgff_id');
        if(Request::instance()->isPost()){
            $mgff_file_name = trim(input('mgff_file_name'), ' ');
            $mgff_file_url = input('mgff_file_url');
            $mgff_file_bmp = input('mgff_file_bmp');
            $update = [
                'mgff_file_name' => $mgff_file_name,
                'mgff_file_bmp' => $mgff_file_bmp
            ];
            if(!empty($mgff_file_url)){
                $update['mgff_file_url'] = $mgff_file_url;
            }
            $res = Db::table('up_match_gf_files')->where('mgff_id', $mgff_id)->update($update);
            if($res){
                return json(['code' => 200, 'msg' => '编辑成功']);
            }else{
                return json(['code' => 100, 'msg' => '编辑失败']);
            }
        }
        $file = Db::table('up_match_gf_files')
            ->field('mgff_file_url, mgff_file_name, mgff_file_bmp')
            ->where('mgff_id', $mgff_id)
            ->find();
        $this->assign([
            'file' => $file,
            'mgff_id' => $mgff_id
        ]);
        $lose = $this->lostTime();
        if($lose == 1){
            return $this->fetch('/lose');
        }else{
            return $this->fetch('match/gffilesedit');
        }
    }
    
    /**
     * 删除官方公告文件
     * @return \think\response\Json
     */
    public function gfFilesDel(){
        $lose = $this->lostTime();
        if($lose == 1){
            return json(['code' => 100, 'msg' => '账号已过期，非法操作']);
        }
        $mgff_id = input('id');
        $res = Db::table('up_match_gf_files')->delete($mgff_id);
        if($res){
            return json(['code' => 200, 'msg' => '删除成功']);
        }else{
            return json(['code' => 100, 'msg' => '删除失败']);
        }
    }
    
    /**
     * 取消比赛
     * @return mixed|\think\response\Json
     */
    public function matchCancel(){
        $match_id = input('match_id');
        if(Request::instance()->isPost()){
            $match_cancel_reason = input('match_cancel_reason');
            $update = [
                'match_status' => 4,
                'match_cancel_reason' => $match_cancel_reason
            ];
            // 退款业务放在定时器中执行
            $res = Db::table('up_match')->where('match_id', $match_id)->update($update);
            if($res){
                return json(['code' => 200, 'msg' => '取消成功']);
            }else{
                return json(['code' => 100, 'msg' => '取消成功']);
            }
        }
        $this->assign('match_id', $match_id);
        return $this->fetch('match/matchcancel');
    }
    
    /**
     * 导出
     * @return \think\response\Json
     */
    public function outExcel(){
        set_time_limit(0);
        $ids = input('ids');
        if($ids == ''){
            return json(['code' => 100, 'msg' => '没有需要导出的数据']);
        }
        $lists = Db::table('up__match_arrive_record')
            ->alias('umar')
            ->join('up__match_detail umd', 'umar.match_detail_id = umd.id', 'left')
            ->join('up_match um', 'umd.match_id = um.match_id', 'left')
            ->join('up_match_group umg', 'umg.mg_id = umd.level_id', 'left')
            ->field('umar.id, umd.match_id, umar.temp_score, umar.sensor_id, umd.turn, umar.start_line_time, 
                umar.start_line_location, umar.start_line_speed, umar.angle, um.match_title, umg.mg_name')
            ->where('umar.id', 'IN', $ids)
            ->order('umar.start_line_time asc')
            ->select();
        foreach($lists as $k => $v){
            // 名次
            $lists[$k]['mc'] = $k + 1;
            // 报名信息
            $sensor = explode('_', $v['sensor_id']);
            $user = Db::table('up_u_user')
                ->where('user_id', $sensor[1])
                ->field('user_phone, user_real_name, user_create_id')
                ->find();
            $apply = Db::table('up_match_apply_info')
                ->join('up_club', 'ma_club_id = club_id', 'left')
                ->where('ma_user_id', $sensor[1])
                ->where('ma_match_id', $v['match_id'])
                ->field('ma_fan_code, club_name')
                ->find();
            // 代表队
            $lists[$k]['club_name'] = $apply['club_name'];
            // 帆号
            $lists[$k]['fan_code'] = $apply['ma_fan_code'];
            // 真实姓名
            $lists[$k]['user_real_name'] = $user['user_real_name'];
            // 手机号
            $lists[$k]['user_phone'] = "\t".$user['user_phone']."\t";
        }
        $cellname = [
            ['mc', '名次', 15, 'LEFT'],
            ['club_name', '代表队', 25, 'LEFT'],
            ['user_real_name', '姓名', 15, 'LEFT'],
            ['fan_code', '帆号', 15, 'LEFT'],
            ['start_line_time', '时间', 20, 'LEFT'],
            ['start_line_location', '位置', 15, 'LEFT'],
            ['start_line_speed', '速度', 15, 'LEFT'],
            ['angle', '角度', 15, 'LEFT'],
            ['match_title', '赛事', 20, 'LEFT'],
            ['mg_name', '组别', 20, 'LEFT'],
        ];
        $res = exportExcel('起航数据', 'setSail', $cellname, $lists);
        return json($res);
    }
}